﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XConductor.Domain.Seedwork.Media;

namespace XConductor.Domain.WP8.Media
{
    public class AudioFormatTransform : MediaFoundationTransform
    {
        public AudioFormatTransform(IAudioSourceProvider sourceProvider, IAudioFormatDescription outputFormat)
            : base(sourceProvider, outputFormat)
        { }

        protected override IMFTransform CreateTransform()
        {
            var items = MediaFoundationApi.EnumerateTransforms(MediaFoundationTransformCategories.AudioEncoder);

            foreach (var item in items)
            {
                object ppv = null;
                try
                {
                    item.ActivateObject(new Guid("bf94c121-5b05-4e6f-8000-ba598961414d"), out ppv);
                    return (IMFTransform)ppv;
                }
                catch
                { }
            }

            return (IMFTransform)null;
        }
    }
}
